﻿<?php
/*
文章管理模块
*/
include_once('../include/top.php');

$action=fs_get_value("do");
$id=fs_get_value("id");
switch($action)
{
	case	"add"	:	add()	;	break;
	case    "edit"  :   add()   ;   break;
	case    "do_add"    :   do_add()    ;   break;
	case	"delete"	:	delete($id)	;	break;
	default				:	main()		;	break;
}




//***********************************************************
//**********************管理文章*****************************
//***********************************************************
function delete($id){
   global $db;
   $result=$db->query("delete from fooeeexam_announcement where announcement_id=".$id);
   $result? fs_showmsg("删除成功!"):fs_showmsg("删除过程中出现错误,请检查!");

}
function main()
{
	global $db;
	//取总条数
	$sql = "select * from fooeeexam_announcement";	
	$result = $db->query($sql);
	$resultcount = $db->num_rows($result);
	//pagebar
	@$page=fs_get_value('p');							//接收页码
	if ($page==null){$page=1;}
	$pagesize=10;								//每页显示数
	$pagecount=ceil($resultcount/$pagesize);	//计算总页
	if ($page>$pagecount){$page=$pagecount;}
	if ($page<1){$page=1;}
	$startnum=($page-1)*($pagesize);
	//pagebarend
?>
<script src="./js/Main.js"></script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
  <tr>
    <th class="CTitle">所有公告</th>
  </tr>
  <tr>
    <td class="CPanel">
<div class="SubMenu"><a href="?do=manage">所有公告</a> | <a href="?do=add">添加公告</a></div>
            <div align="left" style="padding:5px;" id="box">
               <table border="0" cellpadding="0" cellspacing="0" class="TablePanel" align="center" width="100%">
					<tr align="center" height="27">
					  <td class="TDHead" nowrap>序号</td>
					  <td class="TDHead" nowrap>公告标题</td>   
					  <td class="TDHead" nowrap>发布者</td>
                      <td class="TDHead" nowrap>是否显示</td>
					   <td class="TDHead" nowrap>点击次数</td>
					  <td class="TDHead" nowrap>时间</td>
					  <td class="TDHead" nowrap>详细</td>
	                </tr>
<?php
	$result=$db->query("select * from fooeeexam_announcement order by announcement_datatime DESC limit ".$startnum.",$pagesize ");
    $i = 0;
	while($row = $db->fetch_array($result))
	{
		$row['time'] = date("Y-m-d",$row['announcement_datatime']);//时间转换
		//把数字标识 修改成文字
		switch($row['announcement_display']){
		case 0:$row['announcement_display']="否";break;
		default : $row['announcement_display']="是";break;
		}
		$i = $i + 1;
?>
		<tr align="center">
		    <td height="27"><?php echo($i);?></td>
			<td height=20><a href="?do=edit&id=<?php echo($row['announcement_id']);?>" title="点击修改公告" class="lj"><?php echo($row['announcement_title']);?></a></td>
			<td><?php echo($row['announcement_editor']);?></td>
			<td><?php echo($row['announcement_display']);?></td>
			<td><?php echo($row['announcement_hits']);?></td>
			<td><?php echo($row['time']);?></td>
			
			<td><a href="#" onclick="display<?php echo $row['announcement_id'];?>();">查看</a>/<a href="?do=delete&id=<?php echo $row['announcement_id'];?>">删除</a></td>	
			
					<div id="alert<?php echo($row['announcement_id']);?>" class="alert"> 
					<h4><span>反馈内容</span><span id="close" onclick="mclose<?php echo $row['id'];?>();">关闭</span></h4> 

					<?php echo($row['announcement_content']);?>
					</div> 
					<?php 
					//弹出内容框js代码	
					echo ' <script type="text/javascript">  var myAlert = document.getElementById("alert'.$row['id'].'");
                       myAlert.style.display = "none";</script>'; ?>
					   <?php 
	                 echo '<script type="text/javascript"> 
							function display'.$row['announcement_id'].'(){	
							var myAlert = document.getElementById("alert'.$row['announcement_id'].'"); 
							myAlert.style.display = "block"; 
							myAlert.style.position = "absolute"; 
							myAlert.style.top = "50%"; 
							myAlert.style.left = "50%"; 
							myAlert.style.marginTop = "-75px"; 
							myAlert.style.marginLeft = "-150px";
							mybg = document.createElement("div"); 
							mybg.setAttribute("id","mybg"); 
							mybg.style.background = "#000"; 
							mybg.style.width = "100%"; 
							mybg.style.height = "100%"; 
							mybg.style.position = "absolute"; 
							mybg.style.top = "0"; 
							mybg.style.left = "0"; 
							mybg.style.zIndex = "500"; 
							mybg.style.opacity = "0.3"; 
							mybg.style.filter = "Alpha(opacity=30)"; 
							document.body.appendChild(mybg);

							document.body.style.overflow = "hidden"; 
							}
							 function mclose'.$row['id'].'() 
									{ 
									var myAlert = document.getElementById("alert'.$row['announcement_id'].'"); 
									myAlert.style.display = "none"; 
									mybg.style.display = "none"; 
									} 
							
					</script>'; ?>
					
		</tr>
		<tr>
			<td height=1 colspan=9 bgcolor="#E8F1FF" onMouseOver="bgColor='#FF8899'" onMouseOut="bgColor='E7E7E7'"></td>
		</tr>
<?php
	}	
?>
	</table>	
	</div>
	
<center><?php
/*分页示例:

pager(传入URL , 数据总数 , 开始条数 , 每页数目)
*/
echo(pager('?p={page}',$resultcount,$startnum,$pagesize));		
?></center>
	</td>
	</tr>
	</table>

<?php

}
function add(){
	$id = fs_get_value("id");
	if($id != ''){
		global $db;
		$sql = "select * from fooeeexam_announcement where announcement_id = ".$id;
		$result = $db -> query($sql);
		$row = $db -> fetch_array($result);
	}
?>	
<script src="./js/Main.js"></script>
<script>
function check(){
	var title = document.addform.title.value.length;
	var content = FCKeditorAPI.GetInstance('content').EditorDocument.body.innerText.length;
	if (title > 150 || title == 0)
	{
		alert("请把标题的字数控制在0~50个字符之间!");
		return false;
	}
	if (content > 1500 || content == 0)
	{
		alert("请把内容的字数控制在0~500个字符之间!");
		return false;
	}
}
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
		<tr>
		    <th class="CTitle">公告管理</th>
		</tr>	
		<tr>
			<td class="CPanel">
			<div class="SubMenu"><a href="?do=manage">所有公告</a> | <a href="?do=add">添加公告</a>
			</td>
		</tr>	
		<tr>
			<td height="600" valign="top">
			<form name="addform" method="post" action="?do=do_add&id=<?php echo($id);?>">
			<fieldset>
				<legend>添加/编缉公告</legend>
				<div align="left">
					<table border="0" cellpadding="2" cellspacing="1" width="100%">
						<tr>
							<td height="30"><div align="right">公告标题:</div></td>
							<td>
								<input name="title" type="text" size="100" class="text" value="<?php echo($row['announcement_title']);?>"/><font color="red">*</font>不要超过50个字符
							</td>
						</tr>
						<tr>
							<td height="30"><div align="right">是否显示</div></td>
							<td><input type="radio" name="is_display" value=1 <?php if($row['announcement_display'] == 1 || $id == '')echo("checked");?>/>是&nbsp;&nbsp;&nbsp;<input type="radio" name="is_display" value=0 <?php if($row['announcement_display'] == 0 && $row['announcement_display'] != '')echo("checked");?>/>否&nbsp;&nbsp;<font color="red">*</font>公告是否显示出来</td>
						</tr>
						<tr>
							<td valign="top" height="30"><div align="right">公告内容:</div></td>
							<td><?php
                                include("../../fckeditor/fckeditor.php");
                                $oFCKeditor = new FCKeditor('content');
                                $oFCKeditor -> BasePath = "../../fckeditor/";
                                $oFCKeditor -> Value = $row['announcement_content'];
								$oFCKeditor -> Width = '56%';
								$oFCKeditor -> Height = '180';
                                $oFCKeditor -> Create();
	                            ?><font color="red">*</font>内容不要超过500个字符
							</td>
						</tr>
						<tr>
							<td valign="top" height="30"><div align="right"></div></td>
							<td>
				<div class="submit" align="left" style="width:60%; height:30px; line-height:30px;"><input type="submit" name="submit" value="提交" onclick="return check()"/></div></td>
						</tr>
					</table>
				</div>
			</fieldset>
			</form>
			</td>
		</tr>
	</table>
<?php
}
function do_add(){
	global $db;
	$id = fs_get_value("id");
	$title = fs_get_value("title");
	$display = fs_get_value("is_display");
	$content = fs_get_value("content");
	if(strlen($title)>150 || strlen($title)==0){
		fs_showmsg("请把标题的字数控制在0~50个字符之间");
	}
	if(strlen(fs_get_value('content'))>1500 || strlen(fs_get_value('content'))==0){
		fs_showmsg("请把内容的字数控制在0~500个字符之间");
	}
	if($id == ''){
		$sql = "insert into fooeeexam_announcement (announcement_editor,announcement_title,announcement_content,announcement_datatime,announcement_hits,announcement_display) value ('系统','".$title."','".$content."',".time().",0,".$display.")";
		$db -> query($sql);
		fs_showmsg("添加成功！","?");
	}
	else{
		$sql = "update fooeeexam_announcement set announcement_editor = '系统',announcement_title = '".$title."',announcement_content = '".$content."',announcement_datatime = ".time().",announcement_display = ".$display." where announcement_id = ".$id;
		$db -> query($sql);
		fs_showmsg("修改成功！");
	}
}
?>